//
//  ViewController.m
//  MVPDemo
//
//  Created by mobao on 16/6/13.
//  Copyright © 2016年 mobao. All rights reserved.
//

#import "ViewController.h"
#define WEAKSELF typeof(self) __weak weakSelf = self;

@interface ViewController (){
    MyPresenter *presenter;
}

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    //实例化Presenter对象，将页面的传给Presenter
    presenter = [[MyPresenter alloc]initWithViewController:self];

    [self loginResult];
}

//登录事件
- (IBAction)MyBtnClick:(UIButton *)sender{
//    [presenter loginWithAccount:_accountTextF.text password:_passwordTextF.text];
    
    //方式二：
    
//    WEAKSELF
//    [presenter login2WithAccount:_accountTextF.text password:_passwordTextF.text block:^(NSString *info) {
//        weakSelf.infoLabel.text = info;
//    }];
}

//Block实现
-(void)loginResult{
    WEAKSELF
    presenter.loginResult = ^(NSString *info){
        weakSelf.infoLabel.text = info;
    };
}


//触摸空白地方，键盘隐藏
-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
    [_accountTextF resignFirstResponder];
    [_passwordTextF resignFirstResponder];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
